/*
 * Resgister16Bit.java
 *
 * Created on March 19, 2007, 11:13 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package moto9s12sim;

/*
 *
 * @author Fergus Earnshaw
 *
 */

public class Register16bt extends Register{
    
    /** Creates a new instance of Resgister16Bit */
    
    private short sValue;
    
    public Register16bt()
    {
        sValue = 0;
    }
    
    public void setRegister(short sTmp)
    {
        sValue = sTmp;
    }
    
    public void setRegister(byte bHigh, byte bLow)
    {
        
        sValue = (short)((((short)bHigh)*256)+bLow);
        
       
    }
    
    public short getRegister()
    {
        return this.sValue;
    }
    
    public int getUnsignedRegister()
    {
       int iTmp;      
       
       if(this.sValue < 0)
       {
           iTmp = (int)(this.sValue)+(65536);

       }
       else
       {
           iTmp = (int)this.sValue;
       }
       
       return iTmp;
    }
    
    public void inc()
    {
        this.sValue++;
    }

    public void inc(int shTmp)
    {
        this.sValue+=(short)shTmp;
    }
    public void dec()
    {
        this.sValue--;
    }

    public void dec(int shTmp)
    {
        this.sValue-=(short)shTmp;
    }
    public String getHex()
    {
        String strTmp;
        
        strTmp = Integer.toHexString((this.sValue >= 0) ? this.sValue : 65536 + this.sValue).toUpperCase();
        
        while(strTmp.length() < 4)
        {
            strTmp = "0" + strTmp;
        }
        
        return strTmp;
    }
}